/**
 * @param {string} s
 * @return {string}
 */
/**
 * abbaca -> ca
 */
var removeDuplicates = function (s) {
  let stack = [];
  for (let item of s) {
    if (stack[stack.length - 1] === item) {
      stack.pop();
    } else {
      stack.push(item);
    }
  }
  return stack.join('');
};

console.log(removeDuplicates('abbaca'))